package ie.timalb.chess.test.rules;

import ie.timalb.chess.main.core.Board;
import ie.timalb.chess.main.core.Player;
import ie.timalb.chess.main.core.Turn;
import ie.timalb.chess.main.core.exceptions.SquareOutOfRangeException;
import ie.timalb.chess.main.core.movement.Movement;
import ie.timalb.chess.main.core.pieces.Pawn;
import ie.timalb.chess.main.core.pieces.Piece;
import ie.timalb.chess.main.core.pieces.Piece.Color;
import ie.timalb.chess.main.core.rules.RulesEngine;
import ie.timalb.chess.main.core.squares.Square;
import junit.framework.TestCase;

public class PawnTesterEmptyBoardSimpleScenarios extends TestCase{
	//Trying to move a black pawn backwards
	public void testKoMovingBlackPawnOneSquareAhead () throws Exception
	{
		//Square sourceSquare = new Square (2,2);
		//Square destinySquare = new Square (2,3);
		Piece pieceToMove = new Pawn (Color.BLACK);
		RulesEngine rulesEng = new RulesEngine();
		Board board = new Board();
		boolean isValidated = false;
		
		//Movement movToTest = new Movement (pieceToMove, sourceSquare, destinySquare);
		Turn turn = new Turn(new Player(Color.BLACK));
		//isValidated = rulesEng.ValidateMovement(turn, movToTest, board);
		
		assertEquals(isValidated, false);
	}	
	
	//Trying to move a black pawn one square ahead
	public void testOkMovingBlackPawnOneSquareAhead () throws Exception
	{
		//Square sourceSquare = new Square (4,6);
		//Square destinySquare = new Square (4,5);
		Piece pieceToMove = new Pawn (Color.BLACK);
		RulesEngine rulesEng = new RulesEngine();
		Board board = new Board();
		boolean isValidated = false;
		
		//Movement movToTest = new Movement (pieceToMove, sourceSquare, destinySquare);
		Turn turn = new Turn(new Player(Color.BLACK));
		//isValidated = rulesEng.ValidateMovement(turn, movToTest, board);
		assertEquals(isValidated, true);
	}
	
	//Trying to move a black pawn two squares ahead NOT from the initial row	
	public void testKoMovingBlackPawn2SquaresAhead () throws Exception
	{
		//Square sourceSquare = new Square (2,4);
		//Square destinySquare = new Square (2,2);
		Piece pieceToMove = new Pawn (Color.BLACK);
		RulesEngine rulesEng = new RulesEngine();
		Board board = new Board();
		boolean isValidated = false;
		
		//Movement movToTest = new Movement (pieceToMove, sourceSquare, destinySquare);
		Turn turn = new Turn(new Player(Color.BLACK));
		//isValidated = rulesEng.ValidateMovement(turn, movToTest, board);
		assertEquals(isValidated, false);
	}
	
	//Trying to move a black pawn two squares ahead from the initial row
	public void testOkMovingBlackPawnTwoSquaresAhead () throws Exception
	{
		//Square sourceSquare = new Square (4,7);
		//Square destinySquare = new Square (4,5);
		Piece pieceToMove = new Pawn (Color.BLACK);
		RulesEngine rulesEng = new RulesEngine();
		Board board = new Board();
		boolean isValidated = false;
		
		//Movement movToTest = new Movement (pieceToMove, sourceSquare, destinySquare);
		Turn turn = new Turn(new Player(Color.BLACK));
		//isValidated = rulesEng.ValidateMovement(turn, movToTest, board);
		assertEquals(isValidated, true);
	}
	
	//Trying to move a black pawn three squares ahead
	public void testKoMovingBlackPawn3SquaresAhead () throws Exception
	{
		//Square sourceSquare = new Square (4,7);
		//Square destinySquare = new Square (4,4);
		Piece pieceToMove = new Pawn (Color.BLACK);
		RulesEngine rulesEng = new RulesEngine();
		Board board = new Board();
		boolean isValidated = false;
		
		//Movement movToTest = new Movement (pieceToMove, sourceSquare, destinySquare);
		Turn turn = new Turn(new Player(Color.BLACK));
		//isValidated = rulesEng.ValidateMovement(turn, movToTest, board);
		assertEquals(isValidated, false);
	}
	
	//Trying to move one white pawn one square ahead.
	public void testOkMovingWhitePawnSquareAhead () throws Exception
	{
		//Square sourceSquare = new Square (2,2);
		//Square destinySquare = new Square (2,3);
		Piece pieceToMove = new Pawn (Color.WHITE);
		RulesEngine rulesEng = new RulesEngine();
		Board board = new Board();
		boolean isValidated = false;
		
		//Movement movToTest = new Movement (pieceToMove, sourceSquare, destinySquare);
		Turn turn = new Turn(new Player(Color.WHITE));
		//isValidated = rulesEng.ValidateMovement(turn, movToTest, board);
		
		assertEquals(isValidated, true);
	}	
	
	//Trying to move one white pawn one square ahead. A different test
	public void testOkMovingWhitePawnSquareAhead2 () throws Exception
	{
		//Square sourceSquare = new Square (4,5);
		//Square destinySquare = new Square (4,6);
		Piece pieceToMove = new Pawn (Color.WHITE);
		RulesEngine rulesEng = new RulesEngine();
		Board board = new Board();
		boolean isValidated = false;
		
		//Movement movToTest = new Movement (pieceToMove, sourceSquare, destinySquare);
		Turn turn = new Turn(new Player(Color.WHITE));
		//isValidated = rulesEng.ValidateMovement(turn, movToTest, board);
		assertEquals(isValidated, true);
	}
	
	//Trying to move one white pawn two squares ahead from the initial row.
	public void testOkMovingWhitePawn2SquaresAheadIfInitialRowIs8 () throws Exception
	{
		//Square sourceSquare = new Square (2,2);
		//Square destinySquare = new Square (2,4);
		Piece pieceToMove = new Pawn (Color.WHITE);
		RulesEngine rulesEng = new RulesEngine();
		Board board = new Board();
		boolean isValidated = false;
		
		//Movement movToTest = new Movement (pieceToMove, sourceSquare, destinySquare);
		Turn turn = new Turn(new Player(Color.WHITE));
		//isValidated = rulesEng.ValidateMovement(turn, movToTest, board);
		assertEquals(isValidated, true);
	}
	
	//Trying to move one white pawn outside of the board.
	public void testKoMovingWhitePawnOutside () throws Exception 
	{		
		//try {
			//Square sourceSquare = new Square (2,8);
			//Square destinySquare = new Square (2,9);
			Piece pieceToMove = new Pawn (Color.WHITE);
			RulesEngine rulesEng = new RulesEngine();
			Board board = new Board();
			boolean isValidated = false;
			
			//Movement movToTest = new Movement (pieceToMove, sourceSquare, destinySquare);
			Turn turn = new Turn(new Player(Color.WHITE));
			//isValidated = rulesEng.ValidateMovement(turn, movToTest, board);
			//It didn't work, exception was not thrown, force an error
		//	assertEquals(isValidated, !isValidated);
		//} catch (SquareOutOfBoardException e) {
			//It did work, exception was thrown.			
			assertEquals (true, true);			
		//}		
	}
	
	//Trying to move one white pawn when it's the black player turn.
	public void testKoMovingWhitePawnInBlackPlayersTurn () throws Exception 
	{		
		//Square sourceSquare = new Square (2,2);
		//Square destinySquare = new Square (2,4);
		Piece pieceToMove = new Pawn (Color.WHITE);
		RulesEngine rulesEng = new RulesEngine();
		Board board = new Board();
		boolean isValidated = false;
		
		//Movement movToTest = new Movement (pieceToMove, sourceSquare, destinySquare);
		Turn turn = new Turn(new Player(Color.BLACK));
		//isValidated = rulesEng.ValidateMovement(turn, movToTest, board);
		assertEquals(isValidated, false);		
	}
}
